//
//  MovieTwoVC.m
//  豆瓣
//
//  Created by lanou3g on 15/12/12.
//  Copyright © 2015年 HaiTeng. All rights reserved.
//

#import "MovieTwoVC.h"
#import "MyCollectionViewCell.h"
#import "MovieListModel.h"
#import "UIImageView+WebCache.h"
#import "MovieDetailVC.h"


@interface MovieTwoVC ()<UICollectionViewDelegateFlowLayout,UICollectionViewDataSource>
@property(nonatomic,strong)UICollectionView *collectionView;
@property(nonatomic,strong)MovieListModel *modelTwo;
@end

@implementation MovieTwoVC
NSString *CELLID = @"CELLID";
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor grayColor];
    [self setRightBarButtonItem];
    [self setConetView];
}


#pragma mark 导航栏右按钮 及 事件
- (void)setRightBarButtonItem
{
    self.navigationItem.title = @"电影";
    self.navigationController.navigationBar.translucent = NO;
    self.navigationItem.hidesBackButton = YES;
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"btn_nav_list"] landscapeImagePhone:nil style:UIBarButtonItemStylePlain target:self action:@selector(rightBarButtonItemAction:)];
}
- (void)rightBarButtonItemAction:(UIBarButtonItem *)sender
{
   
    [self.navigationController popViewControllerAnimated:YES];
    
}

- (void)setConetView
{
    
     UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    layout.minimumLineSpacing = 10;   //行间距(最小上下间距)
   layout.minimumInteritemSpacing = 10;  //列间距(最小左右间距)
    layout.itemSize = CGSizeMake(100, 150);  //cell(块儿的)大小(尺寸)
    layout.sectionInset = UIEdgeInsetsMake(20, 20, 20, 20);
    
    //二、初始化，创建collectionView
    self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height - 39) collectionViewLayout:layout];
    self.collectionView.backgroundColor = [UIColor whiteColor];
    //三、遵循协议设置代理(两个)
    self.collectionView.delegate = self;
    self.collectionView.dataSource = self;
    
    
     [self.collectionView registerClass:[MyCollectionViewCell class] forCellWithReuseIdentifier:CELLID];
    
     [self.view addSubview:self.collectionView];
}

#pragma mark   两个必须实现的代理方法
//返回每个分组有多少个单元
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    
    return self.dataArrayTwo.count;
    
}

//返回每个单元
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    
    
    MyCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:CELLID forIndexPath:indexPath];
    
    MovieListModel *model = self.dataArrayTwo[indexPath.row];
    cell.label.text = model.movieName;
    
    [cell.imv sd_setImageWithURL:[NSURL URLWithString:model.pic_url]];
    
    return cell;
    
}




#pragma mark 点击事件

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    
    
   
    
    MovieDetailVC *movieDetailVC_ = [[MovieDetailVC alloc] init];
    movieDetailVC_.model = self.dataArrayTwo[indexPath.row]; //传值
    movieDetailVC_.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:movieDetailVC_ animated:YES];
    
    
    
}



@end
